package com.dindang.checkline.mvp.ui.activity.witget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dindang.checkline.R;
import com.longxi.gamer_base.utils.DoubleUtil;
import com.longxi.gamer_base.utils.TextViewUtils;
import com.longxi.gamer_base.widget.EmptyLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cxw on & 2018/11/8
 */
public class TipDialog extends Dialog {

    public TipDialog(@NonNull Context context) {
        super(context);
    }

    public TipDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected TipDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public static class Builder {
        private Context context;
        private OnPaymentListener listener;
        private String tip;

        public Builder(Context context) {
            this.context = context;
        }

        public Builder setTip(String tip){
            this.tip = tip;
            return this;
        }

        public Builder setProperty(OnPaymentListener listener) {
            this.listener = listener;
            return this;
        }

        private ImageView cancel;
        private TextView tv_tip;

        private TipDialog dialog;

        public TipDialog create() {
            dialog = new TipDialog(context);
            View view = LayoutInflater.from(context).inflate(R.layout.tip_dialog_show, null);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);//加上这一句，取消原来的标题栏，没加这句之前，发现在三星的手机上会有一条蓝色的线
            dialog.setContentView(view, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            tv_tip = view.findViewById(R.id.tip);
            cancel = view.findViewById(R.id.cancel);
            tv_tip.setText(tip);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });
            return dialog;
        }


        public void dismiss(){
            if(dialog != null){
                dialog.dismiss();
            }
        }

        public void show(){
            if(dialog != null){
                dialog.show();
            }
        }
    }

    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(layoutParams);
    }

    public interface OnPaymentListener {
        void onClick(String paytype);
    }

}
